
module interio

contains

!-----------------------------------------------------------------------------

subroutine readradek(n,arg)
! cteni radku ze (std.) vstupu a rozdeleni na jednotlive parametry
! oddelene ' ',';',','
! pro chybu vraci n = -2
! pro konec souboru n = -1
integer n
character(len=*) :: arg(:)

integer i,j
character(len=2000) radek

do i=1,size(arg)
  arg(i) = ' '
enddo

read(*,'(A)',err=10,end=20) radek

i = 0; n = 0; j = 0;
do while( i < len(radek) ) 
  i = i + 1;
  if( radek(i:i) == ' ' ) then
    j = 0
  elseif( radek(i:i) == ',' ) then
    j = 0
  elseif( radek(i:i) == ';' ) then
    j = 0
  else
    if( j == 0 .and. n < size(arg) ) n = n + 1
    j = j + 1
    arg(n)(j:j) = radek(i:i)
  endif
enddo
return

10 continue
n = -2
return

20 continue
n = -1   
return
end subroutine

!---------------------------------------------------------------------------

function num(a,err) result(x)
! vraci realnou hodnotu z retezce 'a', pri chybe je n /= 0
real x
character(len=*) :: a
integer err

if( err == 0 ) read(a,*,iostat=err) x
end function

!---------------------------------------------------------------------------

end module
